<?php
    $selectedValues = is_array($selectedValues) ? $selectedValues : [];
    $availableOptions = $useKey ? $fieldOptions : array_unique(array_merge($selectedValues, $fieldOptions));
?>
<!-- Tag List -->
<select
    id="<?= $field->getId() ?>"
    name="<?= $field->getName() ?>[]"
    class="form-control custom-select <?= !count($fieldOptions) ? 'select-no-dropdown' : '' ?> select-hide-selected"
    <?php if (!empty($customSeparators)): ?>data-token-separators="<?= $customSeparators ?>"<?php endif ?>
    <?php if (!empty($placeholder)): ?>data-placeholder="<?= e(trans($placeholder)) ?>"<?php endif ?>
    multiple
    <?= $field->getAttributes() ?>>
    <?php foreach ($availableOptions as $key => $option): ?>
        <?php if (!strlen($option)) continue ?>
        <?php if ($useKey): ?>
            <option value="<?= e($key) ?>" <?= in_array($key, $selectedValues) ? 'selected="selected"' : '' ?>><?= e(trans($option)) ?></option>
        <?php else: ?>
            <option value="<?= e($option) ?>" <?= in_array($option, $selectedValues) ? 'selected="selected"' : '' ?>><?= e(trans($option)) ?></option>
        <?php endif ?>
    <?php endforeach ?>
</select>
